package moni.anyou.com.view.view.dynamics;

import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Bundle;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps2d.AMap;
import com.google.gson.Gson;
import com.readystatesoftware.systembartint.SystemBarTintManager;

import org.json.JSONObject;
import org.kymjs.aframe.http.KJHttp;
import org.kymjs.aframe.http.KJStringParams;
import org.kymjs.aframe.http.StringCallBack;

import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantLock;

import moni.anyou.com.view.R;
import moni.anyou.com.view.amap.LocationService;
import moni.anyou.com.view.base.BaseActivity;
import moni.anyou.com.view.bean.SentPicBean;
import moni.anyou.com.view.bean.request.ReqSentDynamicsBean;
import moni.anyou.com.view.bean.response.base.ResTeamBean;
import moni.anyou.com.view.config.SysConfig;
import moni.anyou.com.view.service.UpFileService;
import moni.anyou.com.view.tool.AppTools;
import moni.anyou.com.view.tool.PermissionTools;
import moni.anyou.com.view.tool.ToastTools;
import moni.anyou.com.view.tool.UploadUtil;
import moni.anyou.com.view.tool.compress.luban.Luban;
import moni.anyou.com.view.tool.compress.luban.OnCompressListener;
import moni.anyou.com.view.view.dynamics.adapter.SendPicAdapter;
import moni.anyou.com.view.view.photo.PhotoDialog;
import moni.anyou.com.view.widget.NetProgressWindowDialog;
import moni.anyou.com.view.widget.dialog.MessgeDialog;
import moni.anyou.com.view.widget.pikerview.view.RelationSeletor;
import moni.anyou.com.view.widget.recycleview.DividerItemDecoration;

public class SendDynamicActivity extends BaseActivity implements View.OnClickListener,AMap.OnMapLoadedListener {
    private NetProgressWindowDialog
            window;
    private RecyclerView rcPic;
    private EditText etContentDynamic;
    private SendPicAdapter mySentPicAdapter;
    private TextView tvTeamName;
    public int isFinishCompressCount = 0;
    private RelativeLayout rlTeamName;
    private LocationService locationService;
    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
;
    public String address = "";
    public String longitude = "";
    public String latitude = "";
    int picSize = 0;
    public String teamId = "0";
    ArrayList<String> picArry  = new ArrayList<>();
    private ArrayList mStringrTeam = new ArrayList<>();
    private RelationSeletor mTeamSeletor;
    public final static String ACTION_TYPE_SERVICE = "action.type.service";
    public final static String ACTION_TYPE_THREAD = "action.type.thread";
    private List<ResTeamBean.TeamBean> teamList;
    private LocalBroadcastManager mLocalBroadcastManager;
    private MyBroadcastReceiver mBroadcastReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_dynamic);
        initState();
        initWindow();
        init();
        initLocationService();

    }

    @Override
    public void initView() {
        super.initView();
        initTitle();
        window = new NetProgressWindowDialog(mBaseActivity);
        tvTitle.setText("");
        tvRight.setText("发送");
        tvRight.setVisibility(View.VISIBLE);
        etContentDynamic = (EditText) findViewById(R.id.et_content_dynamic);
        tvTeamName = (TextView) findViewById(R.id.tv_teamName);
        rlTeamName = (RelativeLayout)findViewById(R.id.rl_teamName);
        rcPic = (RecyclerView) findViewById(R.id.rc_pic);
        initBordcast();
    }

    @Override
    public void setAction() {
        tvRight.setOnClickListener(this);
        ivBack.setOnClickListener(this);
        rlTeamName.setOnClickListener(this);
        mPhotoDialog.setPhotoListener(mPhotoListener);

    }
    @Override
    public void onMapLoaded() {



    }

    @Override
    public void setData() {
        super.setData();
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
        rcPic.addItemDecoration(new DividerItemDecoration(mContext, LinearLayoutManager.HORIZONTAL));
        rcPic.addItemDecoration(new DividerItemDecoration(mContext, LinearLayoutManager.VERTICAL));
        rcPic.setLayoutManager(gridLayoutManager);
        mySentPicAdapter = new SendPicAdapter(this, new SentPicBean());
        mPhotoDialog = new PhotoDialog(mBaseActivity, mySentPicAdapter,PhotoDialog.BigSize);
        rcPic.setAdapter(mySentPicAdapter);
        mySentPicAdapter.setmOnItemClickListener(new SendPicAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, SentPicBean data, int position) {
//                if (position == mySentPicAdapter.getItemCount() - 1) {
                if ("".equals(data.filePathName)) {

                    requestPermission(PermissionTools.camera);

                }

            }
        });
    }


    private void initLocationService() {
        locationService = new LocationService(true);
        locationService.checkRxPermissions(this);
        locationService.setLocationListen(new LocationService.LocationListen() {
            @Override
            public void onListen(AMapLocation location, String result) {
                //Toast.makeText(mContext,  result, Toast.LENGTH_LONG).show();
                longitude = ""+location.getLongitude();
                latitude = ""+location.getLatitude();
                address = location.getAddress();

            }
        });
        locationService.startLocation();

    }

        //选择组团
    private void showTeamData() {
        if (teamList != null) {
            mStringrTeam.clear();
            for (int i = 0; i < teamList.size(); i++) {
                try {

                    mStringrTeam.add(teamList.get(i).teamName);
                } catch (Exception ex) {

                }

            }
            mTeamSeletor = new RelationSeletor(mContext, mStringrTeam, new RelationSeletor.ResultHandler() {
                @Override
                public void handle(String teamName) {
                    String currTeamId = "0";
                    //Toast.makeText(RouteTeamActivity.this,""+teamName,Toast.LENGTH_LONG).show();
                    for (int i = 0; i < teamList.size(); i++) {
                        try {

                            if (teamList.get(i).teamName.equals(teamName)) {
                                {
                                    currTeamId = teamList.get(i).teamID;

                                    break;
                                }
                            }
                        } catch (Exception ex) {


                        }
                    }

                    if (!currTeamId.equals("") && !currTeamId.equals(teamId)) {

                        teamId = currTeamId;
                        tvTeamName.setText(teamName);
                    }

                }

                @Override
                public void handle(int position) {


                }
            });
            mTeamSeletor.show();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getMyTeamData();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_left:
                onBack();
                break;
            case R.id.rl_teamName:
                showTeamData();
                break;
            case R.id.right_tv:
                //if (TextUtils.isEmpty(etContentDynamic.getText())) {
                 //   ToastTools.showShort(mContext, "不能为空");
               //     return;
               // }
              //  HelpBean bean = getPics();
               // if (bean != null) {
               //     mPic = bean.sentpic;
                //    showProgressBar();
                //    picSize = bean.picArray.size();
               //     picArry = bean.picArray;

             //   }
                showProgressBar();
                Message fileInfomsg = new Message();
                fileInfomsg.obj = 0;
                upPicHandler.sendMessage(fileInfomsg);
                break;
        }
    }

    @Override
    public void onBack() {
        super.onBack();
        activityAnimation(RIGHT_OUT);
    }

    //手机高版本样式
    private void initState() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

    }
    //得到所有组团信息
    public void getMyTeamData() {
        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        String cmdPara = "{\"cmd\":\"9\",\"uid\":\"" + SysConfig.uid + "\",\"token\":\"" + SysConfig.token +"\",\"isleader\":\"0\",\"pageno\":\"1\",\"pagesize\":\"100\",\"keyword\":\"\"}";
        params.put("sendMsg", cmdPara);
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {
                try {
                    JSONObject jsonObject = new JSONObject(t);
                    //Toast.makeText(mContext, t, Toast.LENGTH_LONG).show();
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {
                        ResTeamBean temp = new Gson().fromJson(t, ResTeamBean.class);
                        teamList = temp.getList();

                    } else {
                        if (result == -2){
                            AppTools.jumptoLogin(mBaseActivity);
                        }
                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                    }
                } catch (Exception ex) {
                    Toast.makeText(mContext,ex.toString(), Toast.LENGTH_LONG).show();
                }

            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_LONG).show();
            }
        });


    }


    private SystemBarTintManager tintManager;
    //手机高版本样式
    @TargetApi(19)
    private void initWindow() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintColor(Color.parseColor("#FEC600"));

            tintManager.setStatusBarTintEnabled(true);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            try {
                Class decorViewClazz = Class.forName("com.android.internal.policy.DecorView");
                Field field = decorViewClazz.getDeclaredField("mSemiTransparentStatusBarColor");
                field.setAccessible(true);
                field.setInt(getWindow().getDecorView(),
                        Color.TRANSPARENT);
            } catch (Exception e) {
            }
        }

    }

    private String mPic = "";
    ReentrantLock reentrantLock = new ReentrantLock();

    public void postSentDynamics() {

        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        String cmdPara = new ReqSentDynamicsBean("18", SysConfig.uid, SysConfig.token, ReqSentDynamicsBean.TYPEID_ADD, ReqSentDynamicsBean.ARTICLEID_ADD, etContentDynamic.getText().toString(), mPic,address,longitude,latitude,teamId).ToJsonString();
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {
                Log.d(TAG, "onSuccess: " + t);
                try {
                    JSONObject jsonObject = new JSONObject(t);
                    //Toast.makeText(mContext, t, Toast.LENGTH_LONG).show();
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {
                        showProgressBar();
                        Toast.makeText(mContext, "发送成功", Toast.LENGTH_SHORT).show();
                        onBack();
                    } else {
                        if (result == -2){
                            AppTools.jumptoLogin(mBaseActivity);
                        }

                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception ex) {
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_SHORT).show();

                }
                window.closeWindow();
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_SHORT).show();
                window.closeWindow();
            }
        });


    }
    public  String comparese(Context context,final String file) {
        if (new File(file).length() / 1024 > 100) {
            String FileName = SysConfig.uid + "_"+ AppTools.getPhotoFileName() +"_"+ UUID.randomUUID().toString();

            Luban.get(context)
                    .setFilename(FileName)
                    .load(new File(file))  //传人要压缩的图片
                    .putGear(Luban.THIRD_GEAR)      //设定压缩档次，默认三挡
                    .setCompressListener(new OnCompressListener() { //设置回调

                        @Override
                        public void onStart() {
                            // TODO 压缩开始前调用，可以在方法内启动 loading UI
                        }

                        @Override
                        public void onSuccess(File file2) {
                            // TODO 压缩成功后调用，返回压缩后的图片文件

                            picArry.add( file2.getPath());

                            if (mPic.equals("")){
                                mPic = "article/"+file2.getName();
                            }
                            else{
                                mPic += ",article/" +file2.getName();
                            }

                            System.out.println("mPic====="+mPic);
                            isFinishCompressCount = isFinishCompressCount+1;
                        }

                        @Override
                        public void onError(Throwable e) {
                            // TODO 当压缩过去出现问题时调用
                            isFinishCompressCount = isFinishCompressCount+1;
                        }
                    }).launch();    //启动压缩
            //if (file.contains("png")) {
            //     FileName = FileName + ".png";
            // }
            //if (file.contains("jpg")) {
            //    FileName = FileName + ".jpg";
            // }
            //if (file.contains("gif")) {
            //     FileName = FileName + ".gif";
            // }
           // Log.d("TAG", "压缩后的问题名: "+FileName+".jpg");
            //Toast.makeText(mContext, mPic, Toast.LENGTH_SHORT).show();
            return FileName+".jpg";
        } else {
            //Toast.makeText(mContext, mPic, Toast.LENGTH_SHORT).show();
            picArry.add(file);

            if (mPic.equals("")){
                mPic = "article/"+new File(file).getName();
            }
            else{
                mPic += ",article/" + new File(file).getName();
            }
            System.out.println("mPic====="+mPic);
            isFinishCompressCount = isFinishCompressCount+1;
            return file;
        }

    }
    HashMap map = new HashMap();
    class MyHandler extends Handler {
        public MyHandler() {

        }

        public MyHandler(Looper L) {
            super(L);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle b = msg.getData();
            ArrayList<String> result = b.getStringArrayList("result");
            window.closeWindow();
            for (String s : result) {
                if ( map.get(s) != null) {
                    mySentPicAdapter.addPic(new SentPicBean(s, map.get(s).toString()), 0);
                    if (mySentPicAdapter.getItemCount() == 10) {
                        mySentPicAdapter.remove();
                    }
                }
            }

        }


    }
/**
      * 压缩多图
      * @param pathList 传入的为图片原始路径
      */
     private void comparese(final Context context,final  ArrayList<String> pathList){
            window.ShowWindow();
            final Queue<Runnable> taskList = new LinkedList<>();
            final MyHandler handler = new MyHandler();
            class Task implements Runnable {
                String path;

                Task(String path) {
                    this.path = path;
                }

                @Override
                public void run() {
                    if (new File(path).length() / 1024 > 100) {
                        final String FileName = SysConfig.uid + "_"+ AppTools.getPhotoFileName() +"_"+ UUID.randomUUID().toString();

                        Luban.get(context)
                                .setFilename(FileName)
                                .load(new File(path))  //传人要压缩的图片
                                .putGear(Luban.THIRD_GEAR)      //设定压缩档次，默认三挡
                                .setCompressListener(new OnCompressListener() { //设置回调

                                    @Override
                                    public void onStart() {
                                        // TODO 压缩开始前调用，可以在方法内启动 loading UI
                                    }

                                    @Override
                                    public void onSuccess(File file2) {
                                        // TODO 压缩成功后调用，返回压缩后的图片文件

                                        picArry.add( file2.getPath());

                                        if (mPic.equals("")){
                                            mPic = "article/"+file2.getName();
                                        }
                                        else{
                                            mPic += ",article/" +file2.getName();
                                        }

                                        System.out.println("mPic====="+mPic);
                                        isFinishCompressCount = isFinishCompressCount+1;
                                        map.put(path,FileName+".jpg");
                                        if(!taskList.isEmpty()){
                                             Runnable runnable = taskList.poll();
                                             handler.post(runnable);
                                        }
                                        else {
                                            Message msg = new Message();
                                            Bundle b = new Bundle();//
                                            b.putStringArrayList("result", pathList);
                                            msg.setData(b);
                                            handler.sendMessage(msg);
                                        }
                                    }

                                    @Override
                                    public void onError(Throwable e) {
                                        // TODO 当压缩过去出现问题时调用
                                        isFinishCompressCount = isFinishCompressCount+1;
                                    }
                                }).launch();    //启动压缩
                        //if (file.contains("png")) {
                        //     FileName = FileName + ".png";
                        // }
                        //if (file.contains("jpg")) {
                        //    FileName = FileName + ".jpg";
                        // }
                        //if (file.contains("gif")) {
                        //     FileName = FileName + ".gif";
                        // }
                        // Log.d("TAG", "压缩后的问题名: "+FileName+".jpg");
                        //Toast.makeText(mContext, mPic, Toast.LENGTH_SHORT).show();
                        //return FileName+".jpg";
                    } else {
                        //Toast.makeText(mContext, mPic, Toast.LENGTH_SHORT).show();
                        picArry.add(path);

                        if (mPic.equals("")){
                            mPic = "article/"+new File(path).getName();
                        }
                        else{
                            mPic += ",article/" + new File(path).getName();
                        }
                        System.out.println("mPic====="+mPic);
                        map.put(path,path);
                        isFinishCompressCount = isFinishCompressCount+1;
                        if(!taskList.isEmpty()){
                            Runnable runnable = taskList.poll();
                            handler.post(runnable);
                        }
                        else {
                            Message msg = new Message();
                            Bundle b = new Bundle();//
                            b.putStringArrayList("result", pathList);
                            msg.setData(b);
                            handler.sendMessage(msg);
                        }
                       // return file;
                    }
                }
            }
           //循环遍历原始路径 添加至linklist中
           for (String path :pathList){
              taskList.add(new Task(path));
           }

           handler.post(taskList.poll());
     }




    private PhotoDialog mPhotoDialog = null;
    private PhotoDialog.PhotoListener mPhotoListener = new PhotoDialog.PhotoListener() {
        @Override
        public void onSuccess(List<String> photoList) {
            if (null != photoList) {
                isFinishCompressCount = 0;

                comparese(mContext, (ArrayList)photoList);
                /*
                //  final File file = new File(photoList.get(0));s
                int k=0;
                for (String s : photoList) {
                    k++;
                    //Toast.makeText(mContext, "开始压缩"+s, Toast.LENGTH_SHORT).show();
                    System.out.println("s======================"+s);
                    File file = new File(s);
                    if (file.exists()) {
                       comparese(mContext, s);

                       // mySentPicAdapter.addPic(new SentPicBean(s, comparese(mContext, s)), 0);
                    }
                    else{
                        //Toast.makeText(mContext, "文件不存在", Toast.LENGTH_SHORT).show();
                    }
                }


                int k=0;
                for (String s : photoList) {
                    k++;
                    if ( map.get(s) != null) {
                        mySentPicAdapter.addPic(new SentPicBean(s, map.get(s).toString()), 0);
                        if (mySentPicAdapter.getItemCount() == 10) {
                            mySentPicAdapter.remove();
                        }
                    }
                }
                */
            }



        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError() {

        }

        @Override
        public void onFinish() {

        }
    };



    //不需要授权
    @Override
    public void permissionNoNeed(String permissionName) {

        mPhotoDialog.show();
    }

    //权限授权成功
    @Override
    public void permissionSuccess(String permissionName) {
        mPhotoDialog.show();
    }
    //权限被拒绝
    @Override
    public void permissionRefuse(String permissionName) {
        showMsgDialog("您拒绝了本应用访问相册的权限，无法上传头像，是否授权获取权限？", "暂不授权", "立即授权", new MessgeDialog.MsgDialogListener() {
            @Override
            public void OnMsgClick() {

            }

            @Override
            public void OnLeftClick() {

            }

            @Override
            public void OnRightClick() {
                openPermissionSettingPage(0x1111);
            }

            @Override
            public void onDismiss() {

            }
        });
    }

    //权限之前被拒绝
    @Override
    public void permissionAlreadyRefuse(String permissionName) {
        showMsgDialog("您之前拒绝了本应用访问相册的权限，无法上传头像，是否授权获取权限？", "暂不授权", "立即授权", new MessgeDialog.MsgDialogListener() {
            @Override
            public void OnMsgClick() {

            }

            @Override
            public void OnLeftClick() {

            }

            @Override
            public void OnRightClick() {
                openPermissionSettingPage(0x1111);
            }

            @Override
            public void onDismiss() {

            }
        });
    }


   /*
    private HelpBean getPics() {
        ArrayList<String> picInfo = new ArrayList<>();
        String TempStr = "";
        ArrayList<SentPicBean> remps = mySentPicAdapter.getmItems();
        if (remps.size() > 1) {
            int size = remps.size();
            if (size!=9) {
                size = size - 1;
            }
            for (int i = 0; i < size; i++) {


                    //picInfo.add(SysConfig.File_DIR.contains(remps.get(i).newFileNameMap) ? remps.get(i).newFileNameMap : remps.get(i).filePathName);

                    String fileName = remps.get(i).newFileNameMap;
                    String oldFileName = remps.get(i).filePathName;
                    if (fileName.contains(SysConfig.File_DIR)){
                        picInfo.add(remps.get(i).newFileNameMap);
                    }
                    else{
                        picInfo.add(remps.get(i).filePathName);
                    }
                    if (i == size - 1) {
                        TempStr = TempStr + (fileName.contains(SysConfig.File_DIR )? new File(fileName).getName() : new File(oldFileName).getName());
                    } else {
                        TempStr = TempStr + (fileName.contains(SysConfig.File_DIR) ? new File(fileName).getName() : new File(oldFileName).getName()) + ",";
                    }

            }
            HelpBean helpBean = new HelpBean();
            helpBean.picArray = picInfo;

           // for (String s:helpBean.picArray) {
             //   Log.d("文件地址", s);
            //}
            helpBean.sentpic = TempStr;
            //Log.d("TAG", TempStr);
            return helpBean;
        }


        return null;
    }
    */
    /*
    class HelpBean {
        ArrayList<String> picArray;
        String sentpic;
    }
    */
    //int picName;
    private Handler upPicHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
//            if (msg != null) {
//                picName = (Integer) msg.obj;
//                UploadThread m = new UploadThread();
//                new Thread(m).start();
//            }
            window.isShowing();

            if (picArry != null) {

                Intent startIntent = new Intent(mContext, UpFileService.class);
                startIntent.putExtra("picArray", "123");
                startIntent.putStringArrayListExtra("pic", picArry);
                startService(startIntent);
            }
            int delay = 1;
            if (picArry != null){
                delay = picArry.size();
            }
            rcPic.postDelayed(new Runnable() {
                @Override
                public void run() {
                    postSentDynamics();
                }
            }, delay*1000);
        }
    };

    public void notifyEnd() {
        ArrayList<SentPicBean> arrayPic = mySentPicAdapter.getmItems();
        int size = arrayPic.size();
        if (!arrayPic.get(arrayPic.size() - 1).filePathName.equals("") && size == 8) {
            mySentPicAdapter.addPic(new SentPicBean(), 8);
        }

    }


    public SendPicAdapter getMySentPicAdapter() {
        return mySentPicAdapter;
    }

    public void initBordcast() {

        mLocalBroadcastManager = LocalBroadcastManager.getInstance(mContext);
        mBroadcastReceiver = new MyBroadcastReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_TYPE_SERVICE);
        intentFilter.addAction(ACTION_TYPE_THREAD);
        mLocalBroadcastManager.registerReceiver(mBroadcastReceiver, intentFilter);
    }

    public class MyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {

            switch (intent.getAction()) {
                case ACTION_TYPE_SERVICE:
                    ToastTools.showShort(mContext, intent.getStringExtra("status"));
                    break;
                case ACTION_TYPE_THREAD:
                    ToastTools.showShort(mContext, intent.getStringExtra("status"));
                    break;
            }
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLocalBroadcastManager.unregisterReceiver(mBroadcastReceiver);
        if (locationService != null){
            locationService.stopLocation();
        }
    }
}
